<?php
namespace app\common\entity;

use think\Db;
use think\Model;

class Rushgoodslist extends Model
{
    /**
     * @var string 对应的数据表名
     */
    protected $table = 'rush_order_user_list';

   
    #搜索商品
    public function hckGoodsLists($order_id,$keyword,$page,$limit)
    {
        return $this->where('goods_title','like',"%".$keyword."%")->where('rush_order_id',$order_id)->order('createtime desc')->page($page)->limit($limit)->select();
    }
    /*下拉加载商品*/
    public function hcGoodsLists($order_id,$page,$limit)
    {
        return $this->where('rush_order_id',$order_id)->order('createtime desc')->page($page)->limit($limit)->select();
    }
    public function getGoodsLists($page,$limit)
    {
        return $this->order('createtime desc')->page($page)->limit($limit)->select();
    }
    public function hkGoodsLists($keyword,$page,$limit)
    {
        
        return $this->where('goods_title','like',"%".$keyword."%")->order('createtime desc')->page($page)->limit($limit)->select();
    }
    /*
     * 分页商品列表
     * */
    public function getGoodsPages($order_id){

        
        $data1 = $this->where('rush_order_id',$order_id)->select();
        $count = count($data1);
        $data = $this->where('rush_order_id',$order_id)->paginate(20,$count,[
            'query'     => ['id'=>$order_id],
        ]);

        return $data;
    }

    public function getGoodsDetail($goodsId){
        return $this->where(array('id'=>$goodsId))->find();
    }
    public function getUserMobile($user_id){
        return DB::table('user')->where(array('id'=>$user_id))->value('mobile');
    }
    public function getUserName($user_id){
        return DB::table('user')->where(array('id'=>$user_id))->value('nick_name');
    }
  
    /*
     * @param 商品ID
     * 根据商品ID 查询商品图
     * */
    public function getGoodsPic($id){
        $goods = new self();
        $goodsList = $goods->where(array('id'=>$id))->find();
        //提取商品内容中的图片
        $pattern='/<img((?!src).)*src[\s]*=[\s]*[\'"](?<src>[^\'"]*)[\'"]/i';
        preg_match_all($pattern,$goodsList['goods_content'],$out);
        return $out[2];
    }

  
}